package com.example.demo.service.impl;

import com.example.demo.entity.basicdata;
import com.example.demo.entity.deletebasic;
import com.example.demo.mapper.basicdataMapper;
import com.example.demo.service.BasicdataService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BasicdataServiceImpl implements BasicdataService {
    @Resource
    private basicdataMapper basicdataMapper;

    @Override
    public String insert(@RequestBody basicdata basicdata)//插入设备信息
    {
        //查询设备编号是否存在
        basicdata basicdata1=basicdataMapper.SelectWfkeyUkey(basicdata.getWfkey(),basicdata.getUkey());
        if(basicdata1==null)//不存在则插入设备
        {
            int i= basicdataMapper.insert(basicdata);
            if (i > 0)
                return "添加成功";
            else
                return "添加失败";
        }
        else
        {return "设备已存在";}
    }

    @Override
    public List query()
    {
        return basicdataMapper.query();
    }//查询设备信息

    @Override
    public String delete(@RequestBody deletebasic deletebasic)//根据设备编号删除设备
    {
        if(basicdataMapper.delete(deletebasic.getWfkey(),deletebasic.getUkey())==1)
        {
            return "删除成功";
        }
        else {return "删除失败";}
    }

    @Override
    public String update(@RequestBody basicdata basicdata)//更新设备信息
    {
        if(basicdataMapper.update(basicdata)==1)
        {
            return "修改成功";
        }
        else {return "修改失败";}
    }
}
